// ========================== 
// 描述：循环按钮选项
// 作者：MING
// 创建时间：2022/02/26 14:06:48 
// 版本：1.0
// ========================== 
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace UIFrame
{
    public class LoopButtonItem : ButtonItem
    {
        private Text text;
        private int index;
        private int contentsLength;
        //选项内容
        public List<string> Contents = new List<string>();
        public int LoopButtonIndex { get => index; }

        private void Awake()
        {
            //内容文字 放到第二个
            text = transform.GetChild(1).GetComponent<Text>();
            if (text == null)
            {
                Debug.LogWarning("No have text ");
            }
            contentsLength = Contents.Count;
            myAction += DataChange;
        }
    
        public void OnEnable()
        {
            //获取之前的设置
            index = 0;
            text.text = Contents[index];
        }

        private void DataChange()
        {
            if (index == contentsLength - 1)
            {
                index = 0;
            }
            else
            {
                index++;
            }
            text.text = Contents[index];
        }
    }
}